class CreatePostings < ActiveRecord::Migration
  def self.up
    create_table :postings do |t|
      # keys
      t.string    :key
      t.string    :member_key
      t.string    :group_key
      t.integer   :listing_number
      
      # basic fields
      t.string    :title
      t.string    :primary_image_url
      t.decimal   :amount_requested, :precision => 15, :scale => 4
      t.decimal   :borrower_rate, :precision => 15, :scale => 4
      t.float     :percent_funded
      t.integer   :bid_count, :default => 0
      t.datetime  :end_date
      t.decimal   :borrower_apr, :precision => 15, :scale => 4

      # detail fields
      t.integer   :credit_grade
      t.boolean   :is_borrower_homeowner, :default => false
      t.boolean   :is_bank_account_verified, :default => false
      t.decimal   :debt_to_income_ratio, :precision => 15, :scale => 4
      
      # description
      t.string    :description

      # additional fields
      t.integer   :status
      t.integer   :funding_option
      t.string    :borrower_state
      
      t.datetime  :start_date
      t.integer   :duration
      t.decimal   :amount_funded, :precision => 15, :scale => 4
      t.decimal   :amount_remaining, :precision => 15, :scale => 4
      
      t.decimal   :bid_maximum_rate, :precision => 15, :scale => 4
      t.decimal   :borrower_maximum_rate, :precision => 15, :scale => 4
      t.decimal   :group_leader_reward_rate, :precision => 15, :scale => 4
      t.timestamps
      # t.datetime :creationDate
      # t.datetime :lastModifiedDate
      
      # authenticated fields to add later
      # t.string    :employment_status
      # t.integer   :employment_status_duration, :default => 0
      # t.string    :occupation
      # t.string    :income_range
      # t.datetime  :first_recorded_credit_line
      # t.integer   :total_credit_lines, :default => 0
      # t.integer   :open_credit_lines, :default => 0
      # t.integer   :current_credit_lines, :default => 0
      # t.decimal   :bankcard_utilization, :precision => 15, :scale => 4
      # t.decimal   :revolving_credit_balance, :precision => 15, :scale => 4
      # t.integer   :inquiries_last_6_months, :default => 0
      # t.integer   :delinquencies_last_7_years, :default => 0
      # t.integer   :now_delinquent, :default => 0
      # t.decimal   :amount_delinquent, :precision => 15, :scale => 4
      # t.integer   :public_records_last_12_months, :default => 0
      # t.integer   :public_records_last_10_years, :default => 0
    end
  end

  def self.down
    drop_table  :postings
  end
end
